home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Source Code / C / Applications / SML⁄NJ 93+ / Documentation / examples / spread / sheet.sml < prev    next >
Encoding:
Text File  |  1995-12-30  |  749 b   |  32 lines  |  [TEXT/R*ch]

  1. functor Spreadsheet(P : PARSE) : SPREADSHEET =
  2. struct
  3.  open Array infix 9 sub
  4.  
  5.  structure F = P.F
  6.  
  7.  fun array2(i,j,v) =  
  8.     let fun init 0 = nil | init i = array(j,v) :: init(i-1)
  9.    in arrayoflist(init i)
  10.   end
  11.  fun update2(a,i,j,v) = update(a sub i, j, v)
  12.  
  13.  val dim = 10
  14.  
  15.  val vtable = array2(dim,dim,0)
  16.  val ftable = array2(dim,dim,F.eval(P.parse "0"))
  17.  val stable = array2(dim,dim,"0")
  18.  
  19.  fun set(i,j,s) = (update2(ftable,i,j, F.eval(P.parse s));
  20.            update2(stable,i,j,s))
  21.  
  22.  fun for (i,j) f = if i<=j then (f i; for(i+1,j) f) else ()
  23.  
  24.  fun eval() = for(0, dim-1)
  25.             (fn i => for(0, dim-1)
  26.                 (fn j => update2(vtable,i,j,
  27.                               (ftable sub i sub j) vtable)));
  28.  
  29.  fun get(i,j) =  (stable sub i sub j, vtable sub i sub j)
  30. end
  31.  
  32.